package com.bdqn.proxy;
import com.bdqn.dao.Buyer;
//import com.bdqn.service.impl.RealBuyer;
import org.apache.log4j.Logger;
import org.junit.Test;

import java.lang.reflect.Proxy;
public class IntermediaryjdkProxyFactory {
    private Logger logger=Logger.getLogger(IntermediaryjdkProxyFactory.class);
    /**
     * 第三章示例8
     */
    public static <T> T create(Object target){
        IntermediaryInvocationHandler handler=new IntermediaryInvocationHandler();
        handler.setTarget(target);
        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),handler);
    }
        /*@Test
public void test() throws Exception{
        Buyer buyer=IntermediaryjdkProxyFactory.create(new RealBuyer());
        String result=buyer.havealook();
        logger.debug(result);
    }*/
}
